<%@ page language="Java" import="java.util.*,descriptor.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	CompaniesListDescriptor compList = (CompaniesListDescriptor)request.getAttribute("Companies");
	CompanySupsListDescriptor supervisorDes = (CompanySupsListDescriptor)request.getAttribute("SupervisorDes");
	String companyID = (String)request.getAttribute("companyID");
	String viewSupervisors = (String)request.getAttribute("viewSupervisors");
	String error1 = (String)request.getAttribute("error1");
	String error2 = (String)request.getAttribute("error2");
%>

<html>
	<jsp:include page="CareerHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Career Officer" />
	</jsp:include>
	<body OnLoad="showmenu(document.getElementById('smenu4'));">
		<jsp:include page="CareerPageHeader.jsp"></jsp:include>
		<div id="container">
			<jsp:include page="CareerMenu.jsp" ></jsp:include>
			<div id="content">
				<h3 class="posttitle">Career Officer - All Supervisors</h3>
				<div class="entry">
					<%
							int sizeList = compList.sizeCompaniesList(); 
							if(sizeList > 0)
							{
					%>
					<p>Select a company in the list to display its recruiters</p>
					<br>
					<form name="frmcompanyList" method="post" style="margin-left: auto; margin-right: auto;">
						<input type="hidden" name="action" value="viewSupervisor1"> 
						<select OnChange="document.frmcompanyList.submit();" name="companyID">  
							<option value="">Select a company: </option>  
					<%
								
								for(int i=0; i<sizeList; i++)
								{
									String selected = "";
									String compName = compList.getCompanyDescriptors().get(i).getName();
									int compID = compList.getCompanyDescriptors().get(i).getId();
									if(companyID !=null && Integer.parseInt(companyID) == compID)
									{
										selected = "selected";
									}
					%>
							<option value="<%= compID %>" <%= selected %>><%= compName %></option>
					<%			
								}
					%>
						</select>
					</form>
					<br>
					<hr>
					<%
							}
							else
							{ 
								if(error1 != null)
					%>
									<p><%= error1 %></p>
					<%	
							} 
							
							if(viewSupervisors != null)
							{
								if(viewSupervisors.equals("1") && supervisorDes != null)
								{
					%>
						<br>
						<table rules="all">
							<thead>
								<tr>
									<th>SurName</th><th>FirstName</th><th>Email</th><th>Actions</th>
							</thead>
							<tbody>
					<%
							int size = supervisorDes.getCompanySupDescriptors().size();
							for(int i=0 ; i<size ; i++)
							{
					%>
								<tr>	
									<td><%= supervisorDes.getCompanySupDescriptors().get(i).getName() %></td>
									<td><%= supervisorDes.getCompanySupDescriptors().get(i).getFirstName() %></td>
									<td><%= supervisorDes.getCompanySupDescriptors().get(i).getMail() %></td>
									<td>
										<form name="update<%= i %>" method="post">
											<input type="hidden" name="action" value="updateSupervisor">
											<input type="hidden" name="supervisorCompID" value="<%= supervisorDes.getCompanySupDescriptors().get(i).getCompanyId() %>">
											<input type="hidden" name="supervisorID" value="<%= supervisorDes.getCompanySupDescriptors().get(i).getUserId() %>">   
										</form> 
								<a href="javascript:document.update<%= i %>.submit();" title="Upadte <%=  supervisorDes.getCompanySupDescriptors().get(i).getName() %>, <%= supervisorDes.getCompanySupDescriptors().get(i).getFirstName() %>'s Details">Update</a>
								<form name="delete<%= i %>" method="post">
									<input type="hidden" name="action" value="deleteSupervisor">
									<input type="hidden" name="supervisorID" value="<%= supervisorDes.getCompanySupDescriptors().get(i).getUserId() %>"> 
									<input type="hidden" name="supervisorCompID" value="<%= supervisorDes.getCompanySupDescriptors().get(i).getCompanyId() %>">
									<input id="recruiter<%= i %>" type="hidden"  value="<%= supervisorDes.getCompanySupDescriptors().get(i).getName() %>, <%= supervisorDes.getCompanySupDescriptors().get(i).getFirstName() %>">    
								</form> 
								<a href="javascript:openDeleteWindow(document.getElementById('recruiter<%= i %>'),document.delete<%= i %>);" title="Delete <%=  supervisorDes.getCompanySupDescriptors().get(i).getFirstName() %>'s Details">Delete</a>
									</td>
								</tr>
					<%
							}
					%>
							</tbody>
						</table>
					<% 			
								}
							}
							else
							{
								if(error2 != null)
								{				
					%>
									<p style="color:red; font-size: 10px;"><%= error2 %></p>
					<%
								}
							}	
					%>
				</div>
			</div>
			<jsp:include page="CareerPageFooter.jsp"></jsp:include>
		</div>
	</body>
</html>